namespace NHCodeFirst.FluentMapper
{
    using System;
    using HbmModel;

    public class ManyToManyMapper<TMany>
    {
        private readonly Collection collection;

        internal ManyToManyMapper(Collection collection)
        {
            this.collection = collection;
        }

        public ManyToManyMapper<TMany> MapKeys(Action<KeyMapper> mapper)
        {
            if (collection.Key == null)
                collection.Key = new Key();
            mapper(new KeyMapper(collection.Key));
            return this;
        }

        public ManyToManyMapper<TMany> Fetch(Enums.Fetch value)
        {
            collection.ManyToMany.Fetch = value.ToString().ToLower();
            return this;
        }

        public ManyToManyMapper<TMany> NotFound(Enums.NotFound value)
        {
            collection.ManyToMany.NotFound = value.ToString().ToLower();
            return this;
        }

        public ManyToManyMapper<TMany> AddManyColumn(string name, Action<ColumnMapper> mapper = null)
        {
            var column = new Column {Name = name};
            if (mapper != null)
                mapper(new ColumnMapper(column));
            collection.ManyToMany.Columns.Add(column);
            return this;
        }
    }
}